package com.mall.goods.controller;

import com.mall.commons.utils.CommonResult;
import com.mall.goods.service.PmsBrandService;
import com.mall.model.domain.PmsBrand;
import com.mall.model.vo.CommonPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/brand")
public class PmsBrandController {

    @Autowired
    private PmsBrandService pmsBrandService;

    /**
     * 根据品牌名称分页获取品牌列表
     *
     * @return
     */
    @GetMapping("/list")
    public CommonResult list(@RequestParam(value = "keyword", required = false) String keyword,
                             @RequestParam("pageNum") Integer pageNum,
                             @RequestParam("pageSize") Integer pageSize) {
        log.info("keyword:{},pageNum:{},pageSize:{}", keyword, pageNum, pageSize);
        CommonPage commonPage = pmsBrandService.list(keyword, pageNum, pageSize);
        return CommonResult.success(commonPage);
    }

    /**
     * 根据id查询品牌信息
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CommonResult selectById(@PathVariable("id") Integer id) {
        PmsBrand brand = pmsBrandService.selectById(id);
        return CommonResult.success(brand);
    }

    /**
     * 批量更新厂家制造商状态
     *
     * @param id
     * @param factoryStatus
     * @return
     */
    @PostMapping("/update/factoryStatus")
    public CommonResult updateFactoryStatus(@RequestParam ArrayList<Integer> ids, Integer factoryStatus) {
        pmsBrandService.updateFactoryStatus(ids, factoryStatus);
        return CommonResult.success("success");
    }

    /**
     * 批量更新显示状态
     *
     * @param ids
     * @param showStatus
     * @return
     */
    @PostMapping("/update/showStatus")
    public CommonResult updateShowStatus(@RequestParam ArrayList<Integer> ids, Integer showStatus) {
        pmsBrandService.updateShowStatus(ids, showStatus);
        return CommonResult.success("Success");
    }

    /**
     * 更新品牌
     *
     * @param id
     * @param pmsBrandParam
     * @return
     */
    @PostMapping("/update/{id}")
    public CommonResult updateById(@PathVariable("id") Integer id, @RequestBody PmsBrand pmsBrandParam) {
        pmsBrandService.updateById(id, pmsBrandParam);
        return CommonResult.success("success");
    }

    /**
     * 获取全部品牌列表
     *
     * @return
     */
    @GetMapping("/listAll")
    public CommonResult selectAll() {
        List<PmsBrand> pmsBrandList = pmsBrandService.selectAll();
        return CommonResult.success(pmsBrandList);
    }

    @GetMapping("/delete/{id}")
    public CommonResult delete(@PathVariable("id") Integer id) {
        pmsBrandService.delete(id);
        return CommonResult.success("success");
    }

    @PostMapping("/delete/batch")
    public CommonResult deleteBatch(@RequestParam List<Integer> ids) {
        pmsBrandService.deleteBatch(ids);
        return CommonResult.success("success");
    }

    @PostMapping("/create")
    public CommonResult create(@RequestBody PmsBrand pmsBrandParam) {
        pmsBrandService.create(pmsBrandParam);
        return CommonResult.success("success");
    }
}
